package com.onpositive.gamemaker.visualizer;

public class HexagonMath
{
	/**
	 * Math.sqrt(3) / 2; Needed for some hexagon-related calculations
	 */
	public static final double TRIANGLE_MULTIPLIER = Math.sqrt(3) / 2;
	
	private static double [][] hexagonMultipliers = new double[6][2];
	
	static
	{
		for (int i = 0; i < 6; i++) {
			hexagonMultipliers[i][0] = Math.cos(i * 2.0 * Math.PI / 6);
			hexagonMultipliers[i][1] = Math.sin(i * 2.0 * Math.PI / 6);
		}   
	}
	
	/**
	 * Returns hexagon coords array for specified center and radius
	 * @param xCenter x hexagon center coord, in pixels
	 * @param yCenter y hexagon center coord, in pixels
	 * @param hexagonRadius hexagon radius
	 * @return hexagon int points array with size [6][2], where [i][0] is ith x coord and [i][1] - y coord
	 */
	public static int[][] getHexagonCoordsArray(int xCenter, int yCenter, int hexagonRadius)
	{
		int [][] result = new int[6][2];
		for (int i = 0; i < 6; i++) {
			result[i][0] = xCenter + (int) Math.round(hexagonMultipliers[i][0] * hexagonRadius);
			result[i][1] = yCenter + (int) Math.round(hexagonMultipliers[i][1] * hexagonRadius);
		}
		return result;
	}
	
	public static int[] getHexagonCoordArray(int x, int y, int radius)
	{
		int[][] coordsArray = HexagonMath.getHexagonCoordsArray(x + radius, y + radius,radius);
		int[] clipArray = new int[12];
		for (int i = 0; i < coordsArray.length; i++)
		{
			clipArray[i * 2] = coordsArray[i][0];
			clipArray[i * 2 + 1] = coordsArray[i][1];
		}
		return clipArray;
	}
}
